const fp = require('lodash/fp')
const { Maybe, Container } = require('./support')

// 练习一
let maybe = Maybe.of([5, 6, 1])
let ex1 = (functor, increase) => {
    return maybe.map((value) => value.map(num => num + increase))
}

console.log(maybe._value)
console.log(ex1(maybe, 1)._value)

// 练习2

let xs = Container.of(['do', 'ray', 'mi', 'fa', 'so', 'la', 'ti', 'do'])
let ex2 = (functor) => {
    return fp.first(xs._value)
}
console.log(ex2(xs))

// 练习3

let safeProp = fp.curry((x, o) => Maybe.of(o[x]))
let user = { id: 2, name: 'Albert' }
let ex3 = fp.flowRight(fp.first, fc => fc._value, safeProp('name'))
console.log(ex3(user))

// 练习4

console.log(Maybe.of(10).map(parseInt))
console.log(Maybe.of(null).map(parseInt))